package com.example.hans.navigationbyviewpageandradiobutton;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ListView;


import java.util.ArrayList;
import java.util.List;

public class FirstActivity extends AppCompatActivity {

    private List<Contact> contacts = new ArrayList<>();

    public void hideTheTitleBar() {
        if(getSupportActionBar() != null){
            getSupportActionBar().hide();
            getWindow().setFlags(
                    WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN
            );
        }
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.first);
//        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//onCreate里面setContentView之前

        hideTheTitleBar();

        initContacts();

        //使用RecyclerView来布局
//        RecyclerView recyclerView = findViewById(R.id.recycle_view);
//        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
//        recyclerView.setLayoutManager(layoutManager);
//        ContactAdapter contactAdapter = new ContactAdapter(contacts);
//        recyclerView.setAdapter(contactAdapter);


        //使用ListView来布局
        ListView listView = findViewById(R.id.listView);
        ContactAdapterForListView contactAdapterForListView = new ContactAdapterForListView(this,R.layout.contact_item,contacts);
        listView.setAdapter(contactAdapterForListView);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Contact contact = contacts.get(i);
                ChartActivity.actionStart(FirstActivity.this,contact.getName());
            }
        });




    }

    public void initContacts() {
        for (int i = 0; i < 20; i++) {
            contacts.add(new Contact("xiaoz","10086"));
            contacts.add(new Contact("siri","10086"));
        }
    }

//    public void startChartAction() {
//        ChartActivity.actionStart(FirstActivity.this);
//    }

}
